	/**
	 * Add a new related document by document_uid	 
	 * 
	 * @return {$className}
	 */
	public function add{$methodName}ById($documentId, $orderNumber = null)
	{ldelim}
		$document = f_document_Provider::getInstance()->getByUniqueId($documentId);
		return $this->add{$methodName}($document, $orderNumber);
	{rdelim}

	/**
	 * Add a new related document
	 * 
	 * @return {$className}
	 */
	public function add{$methodName}($document, $orderNumber = null)
	{ldelim}		
		if(is_object($document) && $document instanceof {$documentType})
		{ldelim}
			if(!is_array($this->{$variable}))
			{ldelim}
				$this->{$variable} = array();
			{rdelim}
		
			if(!in_array($document, $this->{$variable}))
			{ldelim}
				if(is_null($orderNumber))
				{ldelim}
					$this->{$variable}[] = $document;
				{rdelim}
				else
				{ldelim}
					$this->{$variable}[$orderNumber] = $document;
				{rdelim}
			{rdelim}
		{rdelim}
		else
		{ldelim}
			throw new Exception("Document is not a valid object or from valid model({$documentType})");	
		{rdelim}
		return $this;
	{rdelim}
	
	/**
	 * Get the related documents in array
	 *
	 * @return array {$documentType}
	 */
	public function get{$methodName}()
	{ldelim}
		$relationManager = f_relation_Manager::getInstance();
		return $relationManager->getChilds($this, "{$field}", $this->getLang());
	{rdelim}
	
	/**
	 * Get related documents number
	 * 
	 * @return integer
	 */
	public function get{$methodName}Nb()
	{ldelim}
		return $this->{$variable};
	{rdelim}		
	
	/**
	 * Set the number of related documents
	 * Only used when saving or initialize document
	 */
	protected function set{$methodName}($value)
	{ldelim}
		if(!is_null($value) && is_int($value))
		{ldelim}
			$this->{$variable} = $value;
		{rdelim}
		else
		{ldelim}
			$dbProvider = f_database_Provider::getInstance();
	
			$sql = "SELECT COUNT(`child_id`) FROM `f_relation` WHERE `relation_type`=:relationType AND `lang`=:lang AND `parent_id`=:parentId";
			
			$nbRelations = $dbProvider->setQuery($sql)->execute(array("relationType" => '{$field}', "lang" => $this->getLang(), "parentId" => $this->getUniqueId()))->getQueryResult(PDO::FETCH_COLUMN);
	
			$this->{$variable} = intval($nbRelations);
		{rdelim}
	{rdelim}

